﻿using System;
using Android.App;
using Android.Content;
using Android.Widget;

namespace SCPAK2
{
    public class MyDialog : Dialog
    {
        public string tip = "";
        public TextView content, okbtn, nobtn;
        public bool Cancelable = true;
        public EditText editText;
        public LinearLayout linear;
        private Action<string> okevent; 
        public MyDialog(Context context) : base(context)
        {
            SetContentView(Resource.Layout.MyDialog);
            content = FindViewById<TextView>(Resource.Id.message);
            okbtn = FindViewById<TextView>(Resource.Id.okbtn);
            nobtn = FindViewById<TextView>(Resource.Id.nobtn);
            editText = FindViewById<EditText>(Resource.Id.editText1);
            linear = FindViewById<LinearLayout>(Resource.Id.linearLayout1);
            okbtn.Click += new EventHandler(OkClick);
            nobtn.Click += new EventHandler(NoClick);

        }
        public void OkClick(object obj,EventArgs arg) {
            okevent?.Invoke(editText.Text);
            Dismiss();
        }
        public void NoClick(object obj, EventArgs arg)
        {
            Dismiss();
        }
        public override void SetCancelable(bool flag)
        {
            Cancelable = flag;
            base.SetCancelable(flag);
        }
        public override void Cancel()
        {
            if (Cancelable == false) return;
            base.Cancel();
        }
        public override void Dismiss()
        {
            if (Cancelable == false) return;
            base.Dismiss();
        }
        public void SetEditText(string t, string msg,string defalutText,Action<string> ok=null) {
            linear.Visibility = Android.Views.ViewStates.Visible;
            okevent = ok;
            editText.Text = defalutText;
            SetTitle(t);
            content.Text = msg;
        }

        public void setText(string t, string msg)
        {
            linear.Visibility = Android.Views.ViewStates.Gone;
            SetTitle(t);
            content.Text = msg;
        }
    }
}